﻿using Microsoft.AspNetCore.Mvc;

namespace homework4.Controllers
{
    public class LoginController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Check(String username, String pwd)
        {
            // 登录成功
            if (!String.IsNullOrEmpty(username) && username.Equals("zz") && !String.IsNullOrEmpty(pwd) && pwd.Equals("888"))
            {
                HttpContext.Session.SetString("username", username);
                return RedirectToAction("Index", "Test");
            }
            // 登录失败
            TempData["error"] = "用户名或密码错";
            return RedirectToAction("Index", "Login");
        }

        [Route("Logout")]
        public IActionResult Logout()
        {
            HttpContext.Session.Clear();
            return RedirectToAction("Index", "Home");
        }
    }
}
